use serde_json::Value;


pub fn json_merge(a: &Value, b: &Value) -> Value {
    match (a, b) {
        (&Value::Object(ref a), &Value::Object(ref b)) => {
            let mut merged = a.clone();
            for (key, value) in b {
                merged.entry(key.clone()).or_insert_with(|| value.clone());
            }
            Value::Object(merged)
        },
        (&Value::Array(ref a), &Value::Array(ref b)) => {
            let mut merged = a.clone();
            for value in b {
                merged.push(value.clone());
            }
            Value::Array(merged)
        },
        _ => b.clone(),
    }
}